package jianzhiOfferII;

import java.util.Arrays;

//剑指 Offer II 101. 分割等和子集
public class Num101_canPartition {
    public boolean canPartition(int[] nums) {
        int sum = Arrays.stream(nums).sum();
        if (sum / 2 != 0)return false;
        int target = sum / 2;
        int []dp = new int[20001];
        for (int i = 0; i < nums.length; i++) {
            for (int j = target; j >= nums[i] ; j--) {
                dp[j] = Math.max(dp[j] , dp[j - nums[i]] + nums[i]);
            }
        }
return target == dp[target];

    }
}
